package com.atguigu.gmall.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.xml.crypto.dsig.keyinfo.RetrievalMethod;

/**
 * rabbit的配置类
 */
@Configuration
public class RabbitDefaultConfig {

    /**
     * 新建交换机
     */
    @Bean("myExchange")
    public Exchange myExchange(){
        return ExchangeBuilder.topicExchange("java_exchange").durable(true).build();
    }
    /**
     * 新建队列
     */
    @Bean("myQueue")
    public Queue myQueue(){
        return QueueBuilder.durable("java_queue").build();
    }

    /**
     * 新建绑定
     */
    @Bean
    public Binding myBinding(@Qualifier("myExchange") Exchange myExchange,
                             @Qualifier("myQueue") Queue myQueue){
        return BindingBuilder.bind(myQueue).to(myExchange).with("java.#").noargs();
    }
}
